We will use the PyPlot package to plot with Julia. This notebook has a few examples to get you started. The PyPlot.jl site has excellent documentation for plotting.
Loading the PyPlot module may take a few seconds.
In general, all of the arguments, including keyword arguments, are exactly the same as in Python. (With minor translations, of course, e.g. Julia uses true and nothing instead of Python's True and None.)
The full matplotlib.pyplot API is far too extensive to describe here; see the matplotlib.pyplot documentation for more information. The Matplotlib version number is returned by PyPlot.version.
In [1]:
using PyPlot
In [2]:
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
plot(x, y, color="red", linewidth=2.0, linestyle="--")
title("A sinusoidally modulated sinusoid")
Out[2]:
In [3]:
# Draw (x, y) points
figure(figsize=(5, 5))
θ = collect(0:0.1:2π)
plot(0,0,"b.")
plot(cos(θ), sin(θ), "r.")
plot(0.5cos(θ), 0.5sin(θ), "g.")
Out[3]:
In [8]:
# Draw a histogram
y = randn(10^6)
plt[:hist](y, 50) # We use plt.hist, because it conflicts with the built-in hist
Out[8]:
In [44]:
# Draw a stacked bar chart
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = 1:N # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
p1 = bar(ind, menMeans, width, color="r", yerr=menStd)
p2 = bar(ind, womenMeans, width, bottom=menMeans, color="b", yerr=womenStd)
ylabel("Scores")
title("Scores by group and gender")
xticks(ind+width/2., ("G1", "G2", "G3", "G4", "G5") )
legend( (p1[1], p2[1]), ("Men", "Women") )
Out[44]:
In [6]:
# Plot a random surface
surf(rand(30,40))
Out[6]: